package com.tanhua.dubbo.api;

import com.tanhua.dubbo.utils.IdWorker;
import com.tanhua.model.mongo.FocusUser;
import org.apache.dubbo.config.annotation.DubboService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * Created by IntelliJ IDEA.
 * User: 许志民
 * Date: 2022-01-09
 */
@DubboService
public class FocusUserApiImpl implements FocusUserApi{


    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private IdWorker idWorker;
    @Override
    public void save(FocusUser focusUser) {
//        focusUser.setId(new ObjectId());
        mongoTemplate.save(focusUser);
    }

    @Override
    public void remove(Long uid, Long userId) {
        Query query = Query.query(Criteria.where("userId").is(userId).and("videoUserId").is(uid));
        mongoTemplate.remove(query,FocusUser.class);

    }
}
